//数值转换

const parser = require("@babel/parser");
const traverse = require("@babel/traverse").default;
const types = require("@babel/types");
const generator = require("@babel/generator").default;

const jscode = `var b = 1+2`; //转换为i var b=3;

const ast = parser.parse(jscode);
const visitor = {
    BinaryExpression(path) {
        const {confident,value} = path.evaluate();
        if (!confident || value == "Infinity") return;
            path.replaceWith(types.valueToNode(value));
    }
}

traverse(ast, visitor);
console.log(generator(ast)['code'])




